﻿@using Presentation.Web.Admin
@model Domain.Dto.UserDto
@using (Ajax.BeginForm("add", "user", new AjaxOptions
{
    HttpMethod = "post",
    OnBegin = "checkedAddForm",
    OnFailure = "addFailure",
    OnSuccess = "addSuccess"
}))
{
    <fieldset class="module width_full">
        @Html.Partial("_Form", Model)
    </fieldset> 
    <p>
        @{
    if (Html.HasUiPermission(this.ViewContext, "add"))
    { 
            <input type="submit" value="添加" class="alt_btn module_margin" />
    }
        }
    </p>
}
<script type="text/javascript">
    $(function () {
        $('#customSex').change(function () {
            var res = $(this).val();
            if (res == 1) {
                $('#Sex').val("true");
            } else if (res == 2) {
                $('#Sex').val("false");
            } else {
                $('#Sex').val("true");
            }
        });
    });

    function checkedAddForm() {
        var res = true;
        if ($('#UserName').val() == 0) {
            $('#UserName').focus();
            alert("用户名不能为空");
            res = false;
            return res;
        }
        if ($('#Pwd').val() == "") {
            alert("密码不能为空");
            $('#Pwd').focus();
            res = false;
            return res;
        }
        if ($('#customSex').val() == 0) {
            alert("请选择性别");
            $('#customSex').focus();
            res = false;
            return res;
        }
        return res;
    }

    function addSuccess(res) {
        if (res.success) {
            alert("添加成功");
            window.location.reload();
        }
        else {
            alert(res.message);
        }
    }

    function addFailure() {
        alert("添加失败了T_T！");
    }
</script>
